package com.chenjiagou.controller;


import com.chenjiagou.pojo.Notification;
import com.chenjiagou.service.NotificationService;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/notification")
public class NotificationController {
    @Autowired
    private NotificationService notificationService;

    @GetMapping("/findByUserId/{userId}")
    public List<Notification> findByUserId(@PathVariable("userId") int userId) {
        return notificationService.findNotificationByUserId(userId);
    }

    @PostMapping("/markAsRead/{userId}/{notificationId}")
    public void markAsRead(@PathVariable("userId") int userId,
                           @PathVariable("notificationId") int notificationId) {
        notificationService.insertUserNotification(userId, notificationId);
    }
    @GetMapping("/findUnreadByUserId/{userId}")
    public List<Notification> findUnreadByUserId(@PathVariable("userId") int userId) {
        return notificationService.findUnreadByUserId(userId);
    }
    @DeleteMapping("/delete/{id}")
    public void deleteNotification(@PathVariable("id") int id) {
        notificationService.deleteNotification(id);
    }

}